Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/app/pages/[[locale]]/docs/[...slug].vue
blob: 9bdbac9b449e7faaaf14d107e8c201cd6025e510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!-- SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> -->
<!-- SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1 -->

<script setup lang="ts">
import { chrome } from "~/content/chrome";
import { localeOfPrefix } from "~/content/locales";
import { firstDocPage } from "~/content/site";

definePageMeta({
  validate: (route) =>
    localeOfPrefix(typeof route.params.locale === "string" ? route.params.locale : undefined) !==
    undefined,
});

const route = useRoute();
const { locale, to } = useSiteLocale();
const words = computed(() => chrome[locale.value].docsNav);
const path = computed(() => {
  const slug = route.params.slug;
  const parts = Array.isArray(slug) ? slug : slug ? [slug] : [];
  return `/docs/${parts.filter(Boolean).join("/")}`.replace(/\/$/, "");
});

if (path.value === "/docs") await navigateTo(to(firstDocPage), { redirectCode: 301 });

const { data } = await useAsyncData(
  () => `doc:${locale.value}:${path.value}`,
  async () => {
    const own = await queryCollection(docCollections[locale.value]).path(path.value).first();
    const page = own ?? (await queryCollection("docs_en").path(path.value).first());
    const tree = await loadDocTree(locale.value);
    const [previous, next] = await queryCollectionItemSurroundings("docs_en", path.value, {
      fields: ["title"],
    });
    return { page, english: own === null && locale.value !== "en-US", tree, previous, next };
  },
);

if (!data.value?.page) {
  throw createError({ statusCode: 404, statusMessage: "Page not found", fatal: true });
}

const page = computed(() => data.value!.page!);
const tree = computed(() => data.value!.tree);
const group = computed(() => tree.value.find((g) => g.pages.some((p) => p.path === path.value)));
const titleOf = (target: string, fallback: string) =>
  tree.value.flatMap((g) => g.pages).find((p) => p.path === target)?.title ?? fallback;
const toc = computed(() => page.value.body?.toc?.links ?? []);
const source = computed(() => (page.value as { source?: string }).source);

usePageHead(() => ({
  title: `${page.value.title} · Tazel`,
  description: page.value.description ?? "",
}));
</script>

<template>
  <div class="docs-layout">
    <details class="mobile-tree">
      <summary>
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h10" /></svg>
        {{ words.pages }}
      </summary>
      <DocsTree :groups="tree" :current="path" />
    </details>

    <aside class="sidebar">
      <DocsTree :groups="tree" :current="path" />
    </aside>

    <article class="article">
      <nav class="crumbs" aria-label="Breadcrumb">
        <NuxtLink :to="to(firstDocPage)">{{ words.pages }}</NuxtLink>
        <span v-if="group" aria-hidden="true">/</span>
        <span v-if="group">{{ words.groups[group.key] ?? group.key }}</span>
      </nav>
      <h1>{{ page.title }}</h1>
      <p v-if="data?.english" class="english" lang="en">{{ words.englishOnly }}</p>
      <div
        class="prose"
        :dir="data?.english ? 'ltr' : undefined"
        :lang="data?.english ? 'en' : undefined"
      >
        <ContentRenderer :value="page" />
      </div>

      <nav class="pager">
        <NuxtLink v-if="data?.previous" :to="to(data.previous.path)" class="previous">
          <small>{{ words.previous }}</small>
          <span>{{ titleOf(data.previous.path, data.previous.title) }}</span>
        </NuxtLink>
        <NuxtLink v-if="data?.next" :to="to(data.next.path)" class="next">
          <small>{{ words.next }}</small>
          <span>{{ titleOf(data.next.path, data.next.title) }}</span>
        </NuxtLink>
      </nav>
      <p v-if="source" class="edit">
        <a :href="source">{{ words.edit }}</a>
      </p>
    </article>

    <aside v-if="toc.length" class="toc">
      <p>{{ words.onThisPage }}</p>
      <ul>
        <li v-for="link in toc" :key="link.id">
          <a :href="`#${link.id}`">{{ link.text }}</a>
          <ul v-if="link.children?.length">
            <li v-for="child in link.children" :key="child.id">
              <a :href="`#${child.id}`">{{ child.text }}</a>
            </li>
          </ul>
        </li>
      </ul>
    </aside>
  </div>
</template>

<style scoped>
.docs-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  gap: 48px;
  width: min(100% - 32px, 1400px);
  margin-inline: auto;
}

.sidebar,
.toc {
  position: sticky;
  top: 69px;
  align-self: start;
  max-height: calc(100vh - 69px);
  overflow-y: auto;
  padding-block: 32px;
}

.sidebar {
  padding-inline-end: 16px;
  border-inline-end: 1px solid var(--line);
}

.mobile-tree {
  display: none;
}

.article {
  min-width: 0;
  max-width: 820px;
  padding-block: 32px 96px;
}

.crumbs {
  display: flex;
  gap: 8px;
  color: var(--ink-500);
  font-size: 0.9rem;
}

.crumbs a {
  color: var(--ink-500);
}

h1 {
  margin: 10px 0 0;
  font-size: clamp(2rem, 4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.english {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-inline-start: 4px solid var(--gold);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--ink-700);
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 64px;
}

.pager a {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-950);
}

.pager a:hover {
  border-color: var(--brand-600);
  text-decoration: none;
}

.pager small {
  color: var(--ink-500);
}

.pager span {
  color: var(--link);
  font-weight: 650;
}

.pager .next {
  grid-column: 2;
  text-align: end;
}

.edit {
  margin-top: 24px;
  font-size: 0.9rem;
}

.toc p {
  margin: 0 0 10px;
  color: var(--ink-950);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.toc ul ul {
  padding-inline-start: 12px;
}

.toc a {
  display: block;
  padding: 3px 0;
  color: var(--ink-500);
}

.toc a:hover {
  color: var(--ink-950);
  text-decoration: none;
}

@media (max-width: 1180px) {
  .docs-layout {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 860px) {
  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .sidebar {
    display: none;
  }

  .mobile-tree {
    display: block;
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  .mobile-tree summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-weight: 650;
    cursor: pointer;
    list-style: none;
  }

  .mobile-tree summary::-webkit-details-marker {
    display: none;
  }

  .mobile-tree summary svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
  }

  .mobile-tree > :deep(.tree) {
    padding: 0 8px 10px;
  }
}
</style>